package com.qqt.csr.order.service.event;

import com.qqt.csr.order.entity.OrderDynamic;
import com.qqt.csr.order.service.OrderDynamicService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Author: yang hao
 * @Date: 2024/12/13 17:03
 * @Description: 动态事件监听器
 **/
@Slf4j
@Component
public class DynamicEventListener implements ApplicationListener<DynamicEvent> {

    @Autowired
    private OrderDynamicService orderDynamicService;

    @Override
    public void onApplicationEvent(@NonNull DynamicEvent event) {
        List<OrderDynamic> orderDynamics = event.orderDynamics();
        // 保存动态
        if (orderDynamics == null || orderDynamics.isEmpty()) {
            return;
        }
        orderDynamicService.saveBatch(orderDynamics);
    }

}
